require 'rails_helper'

describe "model_schema_info::Collector" do
  let(:collector) { ModelSchemaInfo::Collector.new(model_names: @model_names) }

  describe "initialize" do

    describe "#all_model_class" do
      before do
        @model_klasses = collector.send(:model_klasses)
      end

      it "eq all model names" do
        expect(@model_klasses).to match_array [Admin::User, Article, Category, Image]
      end

      it "except ActiveRecord::SchemaMigration" do
        expect(@model_klasses.include?(ActiveRecord::SchemaMigration)).to eq false
      end

      it "except 'Table doesn't exist' model" do
        expect(@model_klasses.include?(NoExistTableModel)).to eq false
      end
    end

    describe "#try_find_klass" do

      let(:model_klasses) { collector.send(:model_klasses) }

      describe "don't exist model name" do
        it "eq exit" do
          @model_names = 'No exist model'
          expect { collector }.to raise_error(NameError, "Error: '#{@model_names}' model is not found")
        end
      end

      describe "exist model" do
        context "arg is model" do
          it "arg is article" do
            @model_names = 'article'
            expect(model_klasses).to eq [Article]
          end

          it "arg is Article" do
            @model_names = 'Article'
            expect(model_klasses).to eq [Article]
          end
        end

        context "arg is [model]" do
          it "arg is Article" do
            @model_names = ['article']
            expect(model_klasses).to eq [Article]
          end
        end

        context "arg is [model, model, ....]" do
          it "arg is Article" do
            @model_names = ['article', 'category']
            expect(model_klasses).to match_array [Article, Category]
          end
        end
      end
    end

  end

=begin
  it "show test" do
    expect(ModelSchemaInfo.exec).to eq nil
  end
=end
end
